const TOKEN_KEY = 'token'

const isLogin = () => !!sessionStorage.getItem(TOKEN_KEY)

const getToken = () => sessionStorage.getItem(TOKEN_KEY)
const setToken = (token: string) => {
  sessionStorage.setItem(TOKEN_KEY, token)
}
//设置过期时间
const setExTime = (time = 1000 * 60 * 10) => {
  sessionStorage.setItem('exTime', new Date().getTime() + time + '')
}
//获取过期时间
const getExTime = () => sessionStorage.getItem('exTime')
//判断是否过期
const isEx = () => {
  const time = Number(getExTime())
  if (!time) return false
  const nowTime = new Date().getTime()
  return nowTime > time
}
const clear = () => {
  sessionStorage.clear()
}
export { isLogin, getToken, setToken, clear, setExTime, getExTime, isEx }
